Fix potential NPE in SelectJdkToolchainMojo.getJdkHome() - #184
Closed
elharo wants to merge 1 commit into
Closed
Conversation
…parator() Fixes apache#168 The getJdkHome() method in SelectJdkToolchainMojo had an unchecked null chain that could throw NullPointerException. Each step in the chain (getModel(), getConfiguration(), getChild(), getValue()) is now guarded against null. Also replaces System.lineSeparator() with \n in the error message for consistency.
Contributor
Author
|
Closed - starting over with test-first development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #168
Problem
The
getJdkHome()method inSelectJdkToolchainMojohad an unchecked null chain that could throwNullPointerException:Each call could return null without a guard:
getModel()could return nullgetConfiguration()could return null (causing NPE on cast)(Xpp3Dom)cast could throwClassCastExceptiongetChild("jdkHome")could return nullgetValue()on null would throw NPEThis could occur during
IfSamemode execution.Fix
Added null guards at each step in the chain, returning null if any step is null or the wrong type. Also replaced
System.lineSeparator()with\nin the error message for consistency.